package com.shuoyue.ycgk.ui.mycourse;

import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.BaseMvpActivity;
import com.shuoyue.ycgk.base.ListWithPage;
import com.shuoyue.ycgk.entity.Course;
import com.shuoyue.ycgk.ui.course.CourseAdapter;
import com.shuoyue.ycgk.ui.course.info.CourseInfoActivity;
import com.shuoyue.ycgk.utils.SizeUtil;
import com.shuoyue.ycgk.utils.SpacesItemDecoration;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class OutDatedCourseActivity extends BaseMvpActivity<MyCourseContract.Presenter> implements MyCourseContract.View {
    @BindView(R.id.recycler_view)
    RecyclerView recyclerView;
    @BindView(R.id.refreshlayout)
    SmartRefreshLayout refreshlayout;

    @BindView(R.id.page_title)
    TextView pageTitle;

    CourseAdapter adapter;
    @Override
    protected int getLayoutId() {
        return R.layout.activity_sigle_list;
    }

    @Override
    protected void initView() {
        pageTitle.setText("失效课程");
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.addItemDecoration(new SpacesItemDecoration(SizeUtil.dip2px(mContext, 12), false));
        adapter = new CourseAdapter(null);
        recyclerView.setAdapter(adapter);
        refreshlayout.setEnableLoadMore(false);

        refreshlayout.setOnRefreshListener(refreshLayout -> {
//            mPresenter.getAllCourse(1, baseType.getId(), 1);
            mPresenter.getMyInvalidateCourse();
            refreshLayout.finishRefresh();
        });

        adapter.setOnItemChildClickListener((adapter, view, position) -> {
            Course course = (Course) adapter.getItem(position);
            switch (view.getId()) {
                case R.id.lay_all:
                    startActivity(new Intent(mContext, CourseInfoActivity.class)
                            .putExtra("id", course.getId()));
                    break;
            }
        });
        registEmptyView(adapter);
    }

    @Override
    public void initData() {
        super.initData();
        mPresenter = new MyCourseContract.Presenter();
        mPresenter.attachView(this);
        mPresenter.getMyInvalidateCourse();
    }


    @Override
    public void getMyCourseSuc(List<Course> courses) {
        adapter.resetData(courses);
        refreshlayout.finishRefresh();
        refreshlayout.finishLoadMore();
    }

    @Override
    public void getAllCourseSuc(ListWithPage<Course> list) {
    }



    @OnClick(R.id.back)
    public void onViewClicked() {
        finish();
    }
}
